#!/usr/bin/perl -w
use strict;
use Getopt::Long;

#88888888888888888888888888888888888888888888888888888888888888888888888888888888

#	Usage

#88888888888888888888888888888888888888888888888888888888888888888888888888888888

my $usage = <<'USAGE';

USAGE:

    middle.pl
                --from_line NUMBER
                [--lines NUMBER]
				[--verbose]

        --from_line specifies the point to start printing from
        --lines specifies the number of lines to print
USAGE


#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888

#	Get options

#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
# mandatory


# optional parameters
my $from_line;
my $count_lines = 10;
my $verbose;
my $help;
GetOptions(
			'from_line=i'		=> \$from_line,
			'lines=i'			=> \$count_lines,
			'verbose'			=> \$verbose,
			'help'				=> \$help);

die $usage if ($help);
die $usage unless ($from_line);
die $usage if ($from_line <= 0 or $count_lines <= 0);

print STDERR "[" if $verbose;
my $curr_line = 0;
while (++$curr_line < $from_line)
{
	last unless <>;
	print STDERR '.' if (($curr_line % 10000) == 0 and $verbose);
}
print STDERR "]\n" if $verbose;

die "File was only $curr_line lines long.\n" if ($curr_line < $from_line);

my $print_line = 0;

while (++$print_line <= $count_lines)
{
	my $line = <>;
	last unless $line;
	print $line;
}
